/*
channel
https://www.bilibili.com/video/BV1gf4y1r79E/?p=28&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
*/
package main

import (
	"fmt"
)

func main() {
	defer fmt.Println("main goroutine结束...")
	fmt.Println("channel")

	// 定义一个channel
	c := make(chan int)
	go func() {
		defer fmt.Println("goroutine结束")

		fmt.Println("goroutine 正在运行...")

		c <- 666 // 将666写入c
	}()

	num := <-c // 从c中接收数据，并赋值给num
	fmt.Println("来自子goroutine：", num)
	// runtime.Goexit() // fatal error: no goroutines (main called runtime.Goexit) - deadlock!

	/*
		for {
			time.Sleep(1 * time.Second)
		}*/
}
